package com.jy.adscm.operation.lxcg.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.lxcg.bean.LxcgSupplier;
import com.jy.adscm.operation.lxcg.bean.QueryLxcgSupplier;
import com.jy.adscm.operation.lxcg.mapper.mysql.LxcgSupplierMapper;
import com.jy.adscm.operation.lxcg.service.LxcgSupplierService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 零星供应商基础信息表 服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-08-15
 */
@Service
public class LxcgSupplierServiceImpl extends ServiceImpl<LxcgSupplierMapper, LxcgSupplier> implements LxcgSupplierService {
     @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public Page<LxcgSupplier> selectLxcgSupplier(Page<LxcgSupplier> page, QueryLxcgSupplier queryCgSuppiler) {
        Wrapper<LxcgSupplier> wrapper =new EntityWrapper<>();
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryCgSuppiler.getName(),null)){
            wrapper.like("name",queryCgSuppiler.getName());
        }
        page= super.selectPage(page,wrapper);
        List<LxcgSupplier> records = page.getRecords();
        for (LxcgSupplier record : records) {
            if (AdscmBaseUtils.getInstance().isNotEmpty( record.getCreator(),null)){
                JyUser jyUser = jyUserMapper.selectById(record.getCreator());
                record.setCreator(jyUser.getName());
            }
        }
        page.setTotal(selectCount(wrapper));
        return page;
    }

    @Override
    public List<LxcgSupplier> selectByKeyWords(String name) {
        Wrapper<LxcgSupplier> wrapper=new EntityWrapper<>();
        wrapper.like("name",name);
        List<LxcgSupplier> lxcgSuppliers = super.selectList(wrapper);
        return lxcgSuppliers;
    }
}
